package com.power.sifa.approve.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import com.power.sifa.approve.model.Aprv_process_materials;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;

/**
 * 审批过程材料 持久层(hibernate)
 */

public interface Aprv_process_materialsDao extends JpaRepository<Aprv_process_materials, Serializable>, JpaSpecificationExecutor<Aprv_process_materials>, Repository<Aprv_process_materials, Serializable>, Aprv_process_materialsDaoCustom<Aprv_process_materials, Serializable> {

   @Modifying
   @Transactional
   @Query("delete  from Aprv_process_materials s where  s.id in (:ids) ")
   void removeByIds(@Param("ids") List<Integer> ids);

   @Query(" from Aprv_process_materials s where  s.applyid = :applyid ")
   List<Aprv_process_materials> getByApplyid(String applyid);

   @Query(" from Aprv_process_materials s where  s.applyid = :applyid and s.mattype = :mattype")
   List<Aprv_process_materials> getByApplyid(String applyid, Integer mattype);

   @Query(" from Aprv_process_materials s where  s.attachid = :attachid ")
   Aprv_process_materials getByAttachid(String attachid);

   @Query(" from Aprv_process_materials s where s.mattype in (:mattypes) order by s.createtime desc ")
   List<Aprv_process_materials> getMaterialByMattypes(List<Integer> mattypes);

   @Query(value = "select * from aprv_process_materials s where s.mattype in (:mattypes) and s.createtime > to_date(:createtime, 'YYYY-MM-DD')  order by s.createtime desc ", nativeQuery = true)
   List<Aprv_process_materials> getMaterialByMattypes(List<Integer> mattypes, String createtime);

   @Modifying
   @Transactional
   @Query(" update Aprv_process_materials s set s.attachid = :attachid where s.id = :id")
   void updateAttachid(String id, String attachid);

}
